// pages/pic/pic.js
var app = getApp()
Page({
  data:{
    domain:app.globalData.domain,
    src:''
  },


  onLoad:function(o){
    this.setData({
      album_id:o.album_id,
      album_name:o.album_name,
      album_cover:o.album_cover,
      album_flower:o.album_flower,
      album_collect:o.album_collect,
      album_openid:o.album_openid
    })

    this.GetPics(this.data.album_id,1,0);
    this.Get_UserInfo(o.album_openid);
    this.Get_Collect_Album(o.album_id);
    this.Get_Album_Collect_Count(o.album_id)

  },


//获取全部收藏相册id
  Get_Collect_Album(aid){
    var t = this
    var openid = wx.getStorageSync('openid');
    wx.request({
      url:app.globalData.urls,
      data:{
        GetTypes:'Get_Collect_Albums2',
        openid:openid
      },
      success: function(res) {
        for(var i=0;i<res.data.length;i++){
          if(res.data[i].Collect_Aid == aid){
            var collect_stat = 1
            break;
          }
        }
        if(collect_stat){
          t.setData({
            collect_color:'wheat'
          })
        }
      }
    });
  },

  Get_Album_Collect_Count(aid){
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        GetTypes:'Album_Get_One_Info',
        album_id:aid
      },
      success: function(res) {
        t.setData({
          c_count:res.data.Album_Collect_Count
        })
      }
    });
  },

  loadimgs(e){
    var that = this,
    index = e.currentTarget.dataset.index
    var pictures = new Array()
    for(var i=0;i<this.data.pics.length;i++){
      pictures.push(app.globalData.domain+this.data.pics[i].Picture_Src);
    }
  //  console.log(pictures)
    wx.previewImage({
      current: pictures[index],
      urls: pictures
    })
  },


  Get_UserInfo(openid){
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        'GetTypes':'Get_UserInfo',
        "openid":t.data.album_openid
      },
      success:function(res){
        if(res.data){
          t.setData({
            album_userhead:res.data.User_HeaderImg,
            album_username:res.data.User_UserName
          })
        }
      }
    });
  },




  GetPics(album_id,pnow=1,pcount=0){
    var t = this
    wx.request({
      url:app.globalData.urls,
      data:{
        'GetTypes':'Get_All_Pics',
        'album_id':album_id
      },
      success:function(res){
      //  console.log(res.data)
        t.setData({
          pics:res.data
        })
        wx.setStorageSync('public_pics',res.data);
      //  console.log(wx.getStorageSync('public_pics'))
      }
    })
  },



})